<template>
  <div class="result">
    <van-nav-bar :title="this.$route.query.key + ' 的搜索结果'" />

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.id" :title="item.title"
       @click="$router.push({name:'article',query:{id:item.art_id}})"/>
    </van-list>
  </div>
</template>

<script>
import {searchresultAPI} from '@/api'
export default {
  data() {
    return {
      loading: false,
      finished: false,
      // 保存搜索结果数据的数组
      list: [],
      page:1,
      key:this.$route.query.key
    };
  },

  methods: {

    async onLoad () {
      
      let res = await searchresultAPI({
        page: this.page++,
        per_page:10,
        q:this.key
      })
    //   console.log(res);
    this.list.push(...res.data.data.results)
    this.loading =false
    if(this.list.length>=res.data.data.total_count){
        this.finished =true
    }
    }
  }
};
</script>
<style lang="">
    
</style>